package com.sky.controller.user;

import com.sky.dto.CommentDTO;
import com.sky.dto.CommentPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/comment")
@Slf4j
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 根据博客id查找评论
     * @param commentPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> getByBlogId(CommentPageQueryDTO commentPageQueryDTO) {
        log.info("根据id:{}查找评论",commentPageQueryDTO);
        PageResult pageResult = commentService.getByBlogId(commentPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 增加评论
     * @param commentDTO
     * @return
     */
    @PostMapping
    public Result saveComment(@RequestBody CommentDTO commentDTO) {
        log.info("增加评论：{}",commentDTO);
        commentService.insertComment(commentDTO);

        return Result.success();
    }
}
